#include "common/assert.h"
#include "os/time.h"
#include "win32/lean_windows.h"

static uint64 g_freq = 0;

Time Time::current()
{
	Time result;

	QueryPerformanceCounter((LARGE_INTEGER*) &result.m_ticks);
	ASSERT(result.m_ticks);

	return result;
}

double Time::to_seconds() const
{
	if (g_freq == 0)
	{
		QueryPerformanceFrequency((LARGE_INTEGER*) &g_freq);
	}

	return double(m_ticks) / double(g_freq);
}

double Time::operator-(const Time& rhs) const
{
	double rhs_secs = rhs.to_seconds();
	double this_secs = to_seconds();

	return this_secs - rhs_secs;
}

